package com.example.controller;

import com.example.common.Result;
import com.example.entity.SysMbtiQuestion;
import com.example.entity.SysQuestion;
import com.example.service.SysMbtiQuestionService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/mbti/question")
public class SysMbtiQuestionController {
    @Resource
    private SysMbtiQuestionService sysMbtiQuestionService;

    @GetMapping("/list")
    public Result getAllQuestions() {
        List<SysMbtiQuestion> questions = sysMbtiQuestionService.getAllQuestions();
        return Result.success(questions);
    }

    //分页查询
    @GetMapping("/selectPage")
    public Result selectPage(SysMbtiQuestion sysMbtiQuestion,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize){
        PageInfo<SysMbtiQuestion> pageInfo = sysMbtiQuestionService.selectPage(sysMbtiQuestion,pageNum,pageSize);
        return Result.success(pageInfo);
    }

    @PostMapping("/insert")
    public Result add(@RequestBody SysMbtiQuestion sysMbtiQuestion){
        sysMbtiQuestionService.add(sysMbtiQuestion);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody SysMbtiQuestion sysMbtiQuestion){
        sysMbtiQuestionService.update(sysMbtiQuestion);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        sysMbtiQuestionService.delete(id);
        return Result.success();
    }

    @PostMapping("/submit")
    public Result add(@RequestBody SysQuestion sysQuestion){
        Map<String, Object> submit = sysMbtiQuestionService.submit(sysQuestion);
        return Result.success(submit);
    }

}
